package com.hkts.naturalgas.flow.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.flow.entity.FlowInstanceinfo;
import com.hkts.naturalgas.flow.service.IFlowInstanceinfoService;
import com.hkts.naturalgas.utils.CustomPageUtils;
import com.hkts.naturalgas.utils.Result;
import com.hkts.naturalgas.utils.ResultUtil;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zy
 * @since 2022-08-31
 */
@RestController
@RequestMapping("/performance/flowInstanceinfo")
public class FlowInstanceinfoController {
    private final Logger logger = LoggerFactory.getLogger(FlowInstanceinfoController.class);

    @Autowired
    public IFlowInstanceinfoService iFlowInstanceinfoService;

    /**
     * 分页查询数据
     *
     * @param page             分页信息
     * @param flowInstanceinfo 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getFlowInstanceinfoPageList")
    public Result<Object> getHontUserList(Page<FlowInstanceinfo> page, FlowInstanceinfo flowInstanceinfo) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iFlowInstanceinfoService.selectPage(page, flowInstanceinfo)));
    }

    /**
     * 保存和修改公用的
     *
     * @param flowInstanceinfo 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/flowInstanceinfoSave")
    public Result<Object> flowInstanceinfoSave(FlowInstanceinfo flowInstanceinfo) {
        iFlowInstanceinfoService.saveOrUpdate(flowInstanceinfo);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/flowInstanceinfoGetById")
    public Result<Object> flowInstanceinfoGetById(String id) {
        FlowInstanceinfo byId = iFlowInstanceinfoService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/flowInstanceinfoDelete")
    public Result<Object> hontUserDelete(String id) {
        iFlowInstanceinfoService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/flowInstanceinfoBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iFlowInstanceinfoService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }
    /**
     * 功能描述: <br>
     * 〈〉发起流程
     * @Param: [templateId,hontUserId,hontUserName]
     * @Return: com.hkts.workflow.utils.Result<java.lang.Object>
     * @Author: zhangyong
     * @Date: 2022/9/3 上午11:03
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/initiateProcess")
    public Result<Object> initiateProcess(FlowInstanceinfo flowInstanceinfo) {

        return iFlowInstanceinfoService.initiateProcess(flowInstanceinfo);
    }
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/cancelProcess")
    public Result<Object> cancelProcess(String id) {

        return iFlowInstanceinfoService.cancelProcess(id);
    }

    /**
     *获取待办
     * @return
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/getBackLog")
    public Result<Object> getBackLog() {

        return iFlowInstanceinfoService.getBackLog();
    }

    /**
     * 获取抄送
     * @return
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/getCopy")
    public Result<Object> getCopy() {

        return iFlowInstanceinfoService.getCopy();
    }



}
